package br.ufba.lasid.jitclouds.mda.vo;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import org.apache.thrift.TFieldIdEnum;

public enum MDAFields implements TFieldIdEnum {
    ID((short) 1, "id"), IP((short) 2, "ip"), CREATION_TIME(
            (short) 3, "creationTime"), ID_MACHINE((short) 4, "ID_MACHINE"), 
            STATUS((short) 5, "status"), QUEUE_NAME((short) 6, "queueName");

    private static final Map<String, MDAFields> byName = new HashMap<String, MDAFields>();

    static {
        for (MDAFields field : EnumSet.allOf(MDAFields.class)) {
            byName.put(field.getFieldName(), field);
        }
    }

    public static MDAFields findByThriftId(int fieldId) {
        switch (fieldId) {
        case 1: // ID
            return ID;
        case 2: // IP
            return IP;
        case 3: // CREATION_TIME
            return CREATION_TIME;
        case 4: // ID_MACHINE
            return ID_MACHINE;
        case 5: // STATUS
            return STATUS;
        case 6: // QUEUE_NAME
            return QUEUE_NAME;
        default:
            return null;
        }
    }

    public static MDAFields findByThriftIdOrThrow(int fieldId) {
        MDAFields fields = findByThriftId(fieldId);
        if (fields == null)
            throw new IllegalArgumentException("Field " + fieldId
                    + " doesn't exist!");
        return fields;
    }

    public static MDAFields findByName(String name) {
        return byName.get(name);
    }

    private final short _thriftId;
    private final String _fieldName;

    MDAFields(short thriftId, String fieldName) {
        _thriftId = thriftId;
        _fieldName = fieldName;
    }

    public short getThriftFieldId() {
        return _thriftId;
    }

    public String getFieldName() {
        return _fieldName;
    }
}
